package com.zy.controller;

import com.zy.bean.bo.version.VersionCreateBo;
import com.zy.bean.bo.version.VersionUpdateBo;
import com.zy.service.VersionListService;
import com.zy.util.VersionUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 版本相关的接口
 * @author hanhuafeng
 * @version V1.0
 * @description
 * @date 2023/7/19
 */
@RestController
@RequestMapping("/v1/version")
@RequiredArgsConstructor
public class VersionController {
    private final VersionUtil versionUtil;
    private final VersionListService versionListService;

    /**
     * 创建版本
     *
     * @param versionCreateBo 版本创建bo
     */
    @PostMapping
    public void createVersion(@Validated @RequestBody VersionCreateBo versionCreateBo) {
        versionUtil.createVersion(versionCreateBo.getVersionName(),
                versionCreateBo.getIntroduce(),
                versionCreateBo.getProjectCode());
    }

    /**
     * 更新版本
     *
     * @param versionCode     版本code
     * @param versionUpdateBo 版本更新bo
     */
    @PatchMapping("/{versionCode}")
    public void updateVersion(@PathVariable String versionCode,
                              @Validated @RequestBody VersionUpdateBo versionUpdateBo) {
        versionListService.updateVersion(versionCode, versionUpdateBo);
    }
}
